package createthread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @description:
 * @author: jhy
 * @time: 2021/4/10 21:03
 */

//创建线程方式3：实现Callalble接口，实现call方法
public class CreateThreadDemo3 implements Callable<Integer> {

    @Override
    public Integer call() throws Exception {

        System.out.println("创建线程方式3：实现Callalble接口，实现call方法");
        return 1024;
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {


        FutureTask<Integer> futureTask = new FutureTask<>(new CreateThreadDemo3());

        new Thread(futureTask).start();

        //拿出线程执行的返回值
        Integer res = futureTask.get();
        System.out.println("线程执行完毕的返回值"+res);
    }
}
